<?php
class model_lhbase_appmenu extends gdl_components_basemodel 
{

    public function primarykey() {
        return 'id';
    }

    public function tableName() {
        return 'lhc_app_menu';
    }
	
	 public function getList( $menuId,$field = '*',$appid)
    {
		if(empty($menuId)) return [];
		$menu = $this->select('ruleId in('.implode(',',$menuId).') and status=1 and appId='.$appid, $field,'order by sort asc')->items; // 
		$parentId = [];
		foreach($menu as $v){
			$parentId[] = $v['pid'];
		}
		if(!empty($parentId)){
			$menuFather = $this->select('(ruleId in('.implode(',',$menuId).') or id in('.implode(',',$parentId).')) and status=1 and appId='.$appid, $field,'order by sort asc')->items; //这种查询方式 是防止 总菜单不小心写入数据库了
			$menu = $menuFather;
		}
		return $menu;
    }
	
	public function getMenu($menuId,$appId=1,$identity='gl'){
		if(empty($menuId)) return [];
		$approuters = new model_lhbase_authrule();
		$tableName =  $this->tableName();
		$leftJoin = array(
			$approuters->tableName().' as a' => $tableName.'.routerId=a.id'
		);
		$condition = $tableName.'.appId='.$appId.' and '.$tableName.'.status=1 and '.$tableName.'.nav=1';
		
		if($identity!='zg'){
			
			$condition .=  ' and '.$tableName.'.id in('.implode(',',$menuId).')';
		}
		
		$accessNode = $this->select($condition, $tableName.'.id,'.$tableName.'.menuName moduleName,'.$tableName.'.icon,'.$tableName.'.pid,a.path,a.title,a.name,a.component','order by '.$tableName.'.sort asc', '', $leftJoin)->items;
		return $accessNode;
	}
	
	
}
